Skip to main content
Version: 1.0.0

inviteMemberTeam

Email Templatesโ€‹

New User Template (addNewMemberTeam)

Add New Member Team Template

Existing User Template (addOtherMemberTeam)

Add Other Member Team Template

Function Name: inviteMemberTeam

Author: Domenico Cerone Creation Date: 13/10/2025
Last Reviewer: Domenico Cerone

Trigger: HTTPS (onRequest)

Purpose: Sends invitation emails to team members using a provided email address, with different templates based on whether the user already exists in Firebase Authentication or needs to complete registration.

Detailed Functionalityโ€‹

This Firebase Function performs the following operations in sequence:

1. Environment Detectionโ€‹

  • Determines the current environment (staging/production) from the service account
  • Checks database URL and project ID to identify the correct environment
  • Sets the appropriate base URL for email links

2. Team Data Retrievalโ€‹

  • Receives teamId and email as input parameters
  • Queries the Teams collection to retrieve team document
  • Extracts team name from the name property
  • Uses the provided email parameter directly for profile lookup
  • Validates team existence and data integrity

3. Profile Data Enrichmentโ€‹

  • Retrieves profile data from the Profiles collection using the provided email
  • Constructs full name from firstName and lastName fields
  • Falls back to formatted username from email if profile data is incomplete

4. Notification Preference Checkโ€‹

  • Checks if the user has enabled the inviteMemberTeam notification in their notification preferences
  • Verifies notification_types.inviteMemberTeam field in the profile
  • If notification is disabled (false): returns success without sending email
  • If notification is enabled (true): proceeds with user authentication check
  • Provides clear logging about notification preference status

5. User Authentication Checkโ€‹

  • Checks if the user exists in Firebase Authentication using the email
  • Uses admin.auth().getUserByEmail() to verify user existence
  • Determines which email template to use based on user status

6. Email Template Selection and Sendingโ€‹

For New Users (not in Firebase Auth):

  • Uses template: bd525131-a5a9-11f0-95cc-e23f717f7d6f
  • Generates JWT security token valid for 7 days
  • Includes registration completion link with token
  • Template variables:
    • profile: Full name of recipient
    • nameTeam: Team name
    • url: Base URL for environment
    • token: JWT security token

For Existing Users (already in Firebase Auth):

  • Uses template: a25db440-a5e1-11f0-95cc-e23f717f7d6f
  • Simple notification email without token
  • Template variables:
    • profile: Full name of recipient
    • nameTeam: Team name

7. JWT Token Generation (New Users Only)โ€‹

  • Creates JWT token with the following payload:
    • email: User's email address
    • teamId: Team identifier
    • teamName: Team name
    • invitedAt: Invitation timestamp
  • Token expires after 7 days
  • Uses secret key: ARShades_Studio_Secret_Key_Invite_Token_Security

8. Email Configurationโ€‹

  • Sender: no-reply@arshades.com (ARShades Studio)
  • Service: ZeptoMail with template system
  • Region: europe-central2
  • CORS: Enabled for cross-origin requests

9. Environment-Specific URLsโ€‹

  • Production: studio.arshades
  • Staging: stagingstudio.arshades
  • Automatically detected based on Firebase project configuration

The function ensures that team members receive appropriate invitation emails based on their current status in the system, facilitating smooth onboarding for new users and simple notifications for existing users.

Input (Payload):โ€‹

{
"teamId": "AijTPF2JbKz2c6SxW0uo",
"email": "user@example.com"
}

Required Parameters:

  • teamId (string): The ID of the team document in the Teams collection
  • email (string): The email address of the user to invite to the team

Output (Success):โ€‹

{
"success": true,
"teamId": "AijTPF2JbKz2c6SxW0uo",
"teamName": "Development Team",
"recipientEmail": "newmember@arshades.com",
"recipientName": "John Doe",
"environment": "staging",
"baseUrl": "stagingstudio.arshades",
"userExists": false,
"templateUsed": "new_user",
"tokenGenerated": true,
"message": "Email di invito inviata con successo con token di sicurezza (valido 7 giorni)"
}

Output (Error):โ€‹

{
"success": false,
"error": "Team con ID AijTPF2JbKz2c6SxW0uo non trovato",
"teamId": "AijTPF2JbKz2c6SxW0uo"
}

Testingโ€‹

URL: http://127.0.0.1:5001/arshadesstaging/europe-central2/inviteMemberTeam

Test with Emulator:

  1. Start the Firebase emulator: firebase emulators:start --only functions
  2. Ensure you're using Node.js version 20: nvm use 20
  3. Test with curl:
curl -X POST "http://127.0.0.1:5001/arshadesstaging/europe-central2/inviteMemberTeam" \
-H "Content-Type: application/json" \
-d '{"teamId": "AijTPF2JbKz2c6SxW0uo", "email": "user@example.com"}'

Postman Testing:

{
"teamId": "AijTPF2JbKz2c6SxW0uo",
"email": "user@example.com"
}

Deploy Command:โ€‹

firebase deploy --only functions:inviteMemberTeam

Production URL:โ€‹

Live Function: https://europe-central2-arshades-7e18a.cloudfunctions.net/inviteMemberTeam

This function is called via HTTP POST request with the teamId parameter.